package main

import (
	"context"
	"fmt"
	"gorm.io/driver/postgres"
	"pay/internal/conf"
	"pay/internal/model"
	"pay/pkg/env"
	"pay/pkg/orm"
)

func main() {
	if e := conf.Conf.Init(context.Background()); e != nil {
		fmt.Println(e.Error())
		return
	}
	pg := postgres.Open(conf.Conf.ORM.DSN)
	db, err := orm.NewConnection(conf.Conf.ORM, env.Local, pg)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	migrator := db.Migrator()
	for _, i := range []interface{}{&model.Schedule{}} {
		if migrator.HasTable(i) {
			_ = migrator.DropTable(i)
		}
		err = migrator.AutoMigrate(i)
		if err != nil {
			fmt.Println(err.Error())
			return
		}
	}
}
